Ext.define('Admin.view.main.MainController', {
	        extend : 'Ext.app.ViewController',
	        mixins : ['Admin.view.tree.NaviTreeController'],

	        alias : 'controller.main',

	        setCurrent : function(routes) {
		        // 切换到指定tab
		        var mainmenu = this.getReferences().mainmenu, view = routes.shift();
		        tab = mainmenu.setActiveTab(view);
		        // 创建页面
		        var item = tab.child('component[routeId=' + view + ']')
		        if (!item) {
			        item = Ext.widget(view, {
				                hideMode : 'offsets',
				                routeId : view
			                })
			        tab.add(item);
		        }
		        view = routes.shift();
		        var controller = item.getController();

		        if (controller) {
			        controller.onMainMenuChange && controller.onMainMenuChange(item);
			        if (view && controller.setCurrentView) {
				        return controller.setCurrentView(view);
			        }
		        }

		        return item;
	        },

	        onMainMenuTabChange : function(tabPanel, newCard, oldCard, eOpts) {
		        var me = this, vm = me.getViewModel();
		        // 在主动点击一级菜单时，需要先设置currentView
		        vm.set('currentView', newCard);
		        // 修改地址的hash值，会触发route事件
		        window.location.hash = '#' + me.getView().routeId + '/' + newCard.getItemId();
		        // 控制导航页显示
		        var navitab = me.getReferences().navitab;
		        var items = navitab.items.items, len = items.length, tabs = navitab.tabBar.items.items;
		        navitab.suspendLayouts();
		        try {
			        for (var i = len - 1; i >= 0; i--) {
				        var item = items[i];
				        if (!item.menus || Ext.Array.contains(item.menus, newCard.itemId)) {
					        if (item.isHidden()) { // 不采取记录位置的方式
						        item.tab.show();
						        item.show();
					        }
				        } else {
					        item.tab.hide();
					        item.hide();
				        }
			        }
		        } finally {
			        navitab.resumeLayouts(true);
		        }
	        },

	        onLogout : function(button, e) {
		        Admin.Msg.confirm('确认退出系统？', function(buttonId) {
			                if ('yes' === buttonId) {
				                Admin.Ajax.request({
					                        url : 'rest/oauth/sign/out'
				                        });
			                }
		                });

	        },

	        onChangePasswordClick : function() {
		        this.redirectTo('#changepassword');
	        },

	        onReloadNaviTree : function(view, action, data) {
		        var me = this, navitab = me.getReferences().navitab;
		        var tree = view ? navitab.queryById(view) : navitab.getActiveTab();
		        if (tree.isXType('treepanel')) {
			        var store = tree.getStore(), selected = tree.getSelection();

			        if (0 < selected.length) {
				        store.load({
					                node : selected[0]
				                });
			        } else {
				        store.load();
			        }
		        }
	        }

        });
